package com.cyh.testdesignpattern.state;

import android.util.Log;

import java.util.Random;

//可以抽奖的状态
public class CanRaffleState extends State {
    //初始化时传入活动引用，抽奖分后改变其状态
    RaffleAction action;

    public CanRaffleState(RaffleAction action) {
        this.action = action;
    }

    //当前状态不可以重复扣除积分
    @Override
    public void deductMoney() {
        Log.i("CanRaffleState", "已经扣除过积分，不能重复扣除");
    }

    //当前状态正在抽奖
    @Override
    public boolean raffle() {
        Log.i("CanRaffleState", "正在抽奖，请稍后。。。");
        Random r = new Random();
        int num = r.nextInt(10);
        if(num == 0) {
            //抽中将，进入发放奖品状态
            action.setState(action.getDispenseState());
            return true;
        } else {
            Log.i("CanRaffleState", "很遗憾，没有抽中奖！");
            //将状态改成不能抽奖状态
            action.setState(action.getNoRaffleState());
            return false;
        }
    }

    //当前状态不能发放奖品
    @Override
    public void dispensePrize() {
        Log.i("CanRaffleState", "没中奖，不能发放奖品！");
    }
}
